package delegate4j;

import com.sun.istack.internal.NotNull;

import java.util.ArrayList;
import java.util.concurrent.FutureTask;

public class Callback extends Delegate<ICallback> {
    public Callback(ICallback delegate) {
        super(delegate);
    }

    public void invoke(@NotNull InvokeData data) throws Exception {
        for (ICallback callback : delegates) {
            callback.invoke(data);
        }
    }

    public AsyncResult<Void> invokeAsync(@NotNull InvokeData data) {
        ArrayList<FutureTask<Void>> tasks = new ArrayList<>();
        for (int i = 0; i < delegates.size(); i++) {
            tasks.add(delegates.get(i).invokeAsync(data));
        }
        return new AsyncResult<>(tasks);
    }
}
